############### Configuration area #######################
config.population.name <- "Acipenser gueldenstaedtii"
config.population.area <- "Azov Sea"
config.target_fun <- "mean" # available: mean, median
#config.area_size <- 36600 # define total area size square
config.area_size <- 34400 # 36600 - 2200 (without 3m depths spaces)
config.remove_zeros <- FALSE # remove zero-catch stations from data? TRUE or FALSE value allowed only
config.weight_denum <- 1000000 # weight multiplier. Example for source data in grams, 1000000 will lead to result in tones
config.iter_num <- 10000 # bootstrap iteration number, recommended values: 10k - 100k
config.p_level = 0.95 # confidential level, default p = 0.95
config.report.author <- "Piatinskii M."
############### Configuration area END ###################


# DO NOT TOUCH ANYTHING BELOW IF YOU HAVE NO IDEA WHAT IS GOING ON!!!

library("rmarkdown")
library("dplyr")
# load script
source("package.R")

set.seed(322223)

# load data
#data <- read.csv("input/shad2022_oct.csv", header = TRUE)
#data <- read.csv("input/anchovy2022_august.csv", header = TRUE)
data <- read.csv("input/russian_sturgeon_oct_2023.csv", header = TRUE)
#data <- read.csv("input/tulka2022-2022-august.csv", header = TRUE)
if (!("C" %in% colnames(data))) 
  stop("Column \"C\" not found in survey.csv")

if (!("S" %in% colnames(data)))
  stop("Column \"S\" not found in survey.csv")

if (!("k" %in% colnames(data)))
  stop("Column \"k\" not found in survey.csv")

if (config.remove_zeros) {
  warning("Attention! Remove zero-catch values from data seria")
  data <- data[data$C!=0,]
}


print("Start sweptarea iterations ...")
# fit model
fit <- sweptarea(C = data$C, S = data$S, k = data$k, total_space = config.area_size, dim = config.weight_denum, p = config.p_level, R = config.iter_num, plot = T, func = config.target_fun)
print(paste0("Density distribution mean = ", fit$d.fit$t0))
print(paste0("Biomass = ", round(fit$B,1), ", CI = [", round(fit$B_CI_LOW,1), " - ", round(fit$B_CI_HIGH,1) , "]"))
print("Calculation done!")

# generate report
render("Report.Rmd", quiet = T)
print("See full report in Report.html")